import {
  Body,
  Controller,
  Get,
  HttpException,
  HttpStatus,
  Post,
  Redirect,
} from '@nestjs/common';
import { UserService } from './user.service';

import { CreateUserDTO } from './dto/user.dto';
import { Public } from 'src/auth/decorators/public.decorator';

@Controller('user')
export class UserController {
  constructor(private readonly userService: UserService) {}

  //注册用户
  @Post('/register')
  async createOne(@Body() userInfo: CreateUserDTO) {
    try {
      return await this.userService.createOne(userInfo);
    } catch (err) {
      throw new HttpException(err, HttpStatus.BAD_REQUEST);
    }
  }

  //获取用户信息
  @Get('/info')
  @Redirect('/api/auth/profile', 302) // GET 301是永久重定向，302是临时重定向
  info() {
    return;
  }

  //登录
  @Public()
  @Post('/login')
  @Redirect('/api/auth/login', 307) // POST 308是永久重定向，307是临时重定向
  login() {
    return;
  }
}
